import pygame


class Point:
    def __init__(self, screen, color: str, point, radius=2):
        self.screen = screen
        self.color: str = color
        self.type: str = "point"
        self.x: float = point[0]
        self.y: float = point[1]
        self.r: int = radius

    def move_right(self, x, y=0):
        self.x += x
        self.y += y

    def draw(self):
        screen = self.screen
        MAX_W = screen.get_width()
        MAX_H = screen.get_height()
        MIN_W = 0
        MIN_H = 0
        if self.x > MAX_W or self.x < MIN_W or self.y > MAX_H or self.y < MIN_H:
            return
        pygame.draw.circle(screen, self.color, (self.x, self.y), self.r)


class Line:
    def __init__(self, screen, color: str, point1, point2):
        self.screen = screen
        self.type: str = "line"
        self.x1: float = point1[0]
        self.y1: float = point1[1]
        self.x2: float = point2[0]
        self.y2: float = point2[1]
        self.color: str = color

    def move_right(self, x, y):
        self.x1 += x
        self.y1 += y
        self.x2 += x
        self.y2 += y

    def draw(self):
        screen = self.screen
        MAX_W = screen.get_width()
        MAX_H = screen.get_height()
        # 如果超出屏幕范围，则不绘制
        if (
            (self.x1 > MAX_W and self.x2 > MAX_W)
            or (self.y1 > MAX_H and self.y2 > MAX_H)
            or (self.x1 < 0 and self.x2 < 0)
            or (self.y1 < 0 and self.y2 < 0)
        ):
            return
        pygame.draw.line(screen, self.color, (self.x1, self.y1), (self.x2, self.y2), 2)


class Circle:
    def __init__(self, screen, color: str, point, radius, width=0):
        self.screen = screen
        self.color: str = color
        self.type: str = "circle"
        self.x: float = point[0]
        self.y: float = point[1]
        self.r: float = radius
        self.width: int = width

    def move_right(self, x, y=0):
        self.x += x
        self.y += y

    def draw(self):
        screen = self.screen
        MAX_W = screen.get_width() + self.r
        MAX_H = screen.get_height() + self.r
        MIN_W = -self.r
        MIN_H = -self.r
        if self.x > MAX_W or self.x < MIN_W or self.y > MAX_H or self.y < MIN_H:
            return
        pygame.draw.circle(screen, self.color, (self.x, self.y), self.r, self.width)


class Rect:
    def __init__(self, screen, color: str, attr, width=0):
        self.screen = screen
        self.color: str = color
        self.type: str = "rect"
        self.x: float = attr[0]
        self.y: float = attr[1]
        self.w: float = attr[2]
        self.h: float = attr[3]
        self.width: int = width

    def move_right(self, x, y=0):
        self.x += x
        self.y += y

    def draw(self):
        screen = self.screen
        MAX_W = screen.get_width() + self.w
        MAX_H = screen.get_height() + self.h
        MIN_W = -self.w
        MIN_H = -self.h
        if self.x > MAX_W or self.x < MIN_W or self.y > MAX_H or self.y < MIN_H:
            return
        pygame.draw.rect(
            screen, self.color, (self.x, self.y, self.w, self.h), self.width
        )
